// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
    env: cloud.DYNAMIC_CURRENT_ENV
}) // 使用当前云环境

const db = cloud.database()

// 云函数入口函数
exports.main = async (event, context) => {
    try {
        // 存储数据
        let data = {
            ...event.data
        }

        const res = db.collection('couponList').doc(data._id).remove()

        if (res.errMsg = "document.remove:ok") {
            return {
                code: 200,
                msg: "删除成功",
            }
        } else {
            return {
                code: 401,
                data,
                msg: "删除失败",
            }
        }
    } catch {
        return {
            code: 401,
            data,
            msg: "删除失败",
        }
    }
}